package com.ddh.codeduck.controller;


import com.ddh.codeduck.infra.minio.utils.MinioUtils;
import com.ddhcodeduck.common.result.BaseResponse;
import com.ddhcodeduck.common.result.ResultUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author 董代恒
 * @version 1.0
 */
@RestController
@RequestMapping("/file")
@Slf4j
@Api(tags = "Minio文件上传")
public class MinioFileController {
    @Resource
    private MinioUtils minioUtils;

    @PostMapping("/upload")
    public BaseResponse<String> upload(MultipartFile file) {
        log.info("开始上传文件");
        String uploadUrl = minioUtils.upload(file);
        log.info("上传成功，文件地址为：{}", uploadUrl);
        return ResultUtils.success(uploadUrl);
    }
}


